const mongoose = require('mongoose')

const { mongopath } = require('../config/config.default')

// sudo mongod --dbpath ~/data/db --logpath ~/data/log/mongodb/mongo.log

async function main() {
	await mongoose.connect(mongopath)
}

main()
	.then((res) => {
		console.log('mongo 链接成功')
	})
	.catch((err) => {
		console.log('mongo 链接失败', err)
	})

module.exports = {
	User: mongoose.model('User', require('./userModel'))
}

// const user = new mongoose.Schema({
// 	username: {
// 		type: String,
// 		required: true
// 	},
// 	age: {
// 		type: Number,
// 		required: true
// 	}
// })

// const userModel = mongoose.model('User', user)
// const u = new userModel({ username: 'lisi', age: 18 })
// u.save()
